package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Digest;

public class DigestDAOImpl extends BaseHibernateDAOImpl<Digest> implements DigestDAO {

	public Digest getDigestByDigestID(String digestID) {
		Digest digest;
		try {
			digest = (Digest) getSession().get(Digest.class, digestID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return digest;
	}

	@SuppressWarnings("unchecked")
	public List<Digest> getAllDigest() {
		List<Digest> digests;
		try {
			Query query = getSession().getNamedQuery("AllDigestQuery");
			digests = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return digests;
	}

	@SuppressWarnings("unchecked")
	public List<Digest> getAllDigestByPage(int currentPage, int lineSize) {
		List<Digest> digests;
		try {
			Query query = getSession().getNamedQuery("AllDigestByPageQuery");
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			digests = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return digests;
	}

}
